package com.bzd.controller;

import com.bzd.common.ApplicationContextHelper;
import com.bzd.common.JsonData;
import com.bzd.dao.SysAclModuleMapper;
import com.bzd.exception.ParamException;
import com.bzd.exception.PermissionException;
import com.bzd.model.SysAclModule;
import com.bzd.param.TestVo;
import com.bzd.util.BeanValidator;
import com.bzd.util.JsonMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Created by Admin on 2020/1/3
 */
@Controller
@RequestMapping("/test")
@Slf4j
public class TestController {

    @RequestMapping("hello.json")
    @ResponseBody
    public JsonData hello(){

        log.info("hello");
        throw new PermissionException("test exception");
//        return JsonData.success("hello,permission");

    }

    @RequestMapping("validate.json")
    @ResponseBody
    public JsonData validate(TestVo vo) throws ParamException {

        log.info("validate");
        SysAclModuleMapper moduleMapper =ApplicationContextHelper.popBean(SysAclModuleMapper.class);
        SysAclModule module = moduleMapper.selectByPrimaryKey(1);
        log.info(JsonMapper.objToString(module));
        BeanValidator.check(vo);
        return JsonData.success("test validate");

    }
}
